package com.qf.Service.Impl;/*
 *
 */

import com.qf.Dao.CartDao;
import com.qf.Dao.GoodsDao;
import com.qf.Dao.Impl.CartDaoImpl;
import com.qf.Dao.Impl.GoodsDaoImpl;
import com.qf.Domain.Cart;
import com.qf.Domain.Goods;
import com.qf.Service.CartsService;

import java.util.List;

public class CartServiceImpl implements CartsService {
    private CartDao cartDao=new CartDaoImpl();
    @Override
    public void add(Cart cart) {
        cartDao.insert(cart);
    }

    @Override
    public List<Cart> fingById(Integer uid) {
        List<Cart> carts = cartDao.select(uid);
        GoodsDao goodsDao=new GoodsDaoImpl();
        for (Cart cart : carts) {
            Integer pid = cart.getPid();
            Goods goods = goodsDao.selectById(pid);
            cart.setGoods(goods);
        }
        return carts;
    }

    @Override
    public Cart findByUidAndPid(Integer uid, Integer pid) {
        Cart cart = cartDao.selectByUidAndPid(uid, pid);
        return cart;
    }

    @Override
    public void modify(Cart cart) {
        cartDao.updata(cart);
    }

    @Override
    public void delete(Integer uid, int pid) {
        cartDao.delete(uid,pid);
    }

    @Override
    public void delete(Integer uid) {
        cartDao.delete(uid);
    }
}
